import { withInstall } from '@/utils';
import vxeBasicTable from './src/VxeBasicTable';
import { VxeUI } from 'vxe-table';
import VXETablePluginAntd from './src/components';
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx';
import ExcelJS from 'exceljs';
import './src/setting';
import { h } from 'vue';
import { componentMap } from '../view/componentMap';
import { TableAction } from '../Table';

export const VxeBasicTable = withInstall(vxeBasicTable);
export * from 'vxe-table';
export * from './src/types';

VxeUI.use(VXETablePluginAntd).use(VXETablePluginExportXLSX, { ExcelJS });

// 注册@/components/view/下面所有列渲染器
componentMap.forEach((comp, key) => {
  // 创建一个渲染器
  VxeUI.renderer.add(key, {
    // 默认显示模板
    renderDefault(renderOpts, params) {
      const { row, column } = params;
      return h(comp, {
        ...renderOpts.props,
        value: row[column.field],
      });
    },
  });
});
// 创建一个简单的工具栏-左侧按钮渲染
VxeUI.renderer.add('TableAction', {
  renderToolbarButton(renderOpts) {
    return h(TableAction, renderOpts.props);
  },
});
